#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

class Glob:

  
  # SITE PATH
  SITE_PATH = u"/home/lugocreation/public_html/comics/"

  
  # LOGS FILE PATH
  LOG_FILENAME = SITE_PATH + u"log/logging_comics.out"


  # INI FILE PATH
  INI_FILENAME = SITE_PATH + u"comics.ini"


  # CONNECT DB
  dbName = u"comics_cms"           
  user   = u"comics_cms"           
  passwd = u"admindb"               
  host   = u"127.0.0.1"   


  # CREATE TABLES
  dicTables = {"cms_user": "CREATE TABLE IF NOT EXISTS `cms_user` (\n`id` INT(11) NOT NULL AUTO_INCREMENT,\n`user_name` VARCHAR(30) NOT NULL,\n`user_password` VARCHAR(40) NOT NULL,\nPRIMARY KEY (`id`),\nUNIQUE(`user_password`)\n) TYPE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;\n\n",
              "cms_nav": "CREATE TABLE IF NOT EXISTS `cms_nav` (\n`id` INT(11) NOT NULL AUTO_INCREMENT,\n`nav_name` VARCHAR(30) NOT NULL,\n`nav_title` VARCHAR(50) NOT NULL,\n`nav_parent_id` INT(11) DEFAULT 0,\n`nav_position` INT(3) DEFAULT 0,\n`nav_onclick` VARCHAR(50) DEFAULT 'goPage(this.id)',\n`nav_selected` TINYINT(1) NOT NULL DEFAULT 0,\n`page_id` INT(11) NOT NULL,\nPRIMARY KEY (`id`) \n) TYPE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;\n\n",
              "cms_page": "CREATE TABLE IF NOT EXISTS `cms_page` (\n`id` INT(11) NOT NULL AUTO_INCREMENT,\n`page_title` VARCHAR(30) NOT NULL,\n`page_content` TEXT NOT NULL,\n`nav_id` INT(11) NOT NULL,\nPRIMARY KEY (`id`) \n) TYPE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;\n\n",
              "cms_config": "CREATE TABLE IF NOT EXISTS `cms_config` (\n`id` INT(11) NOT NULL AUTO_INCREMENT,\n`config_title` VARCHAR(30) DEFAULT 'Comics' NOT NULL,\n`config_pub` VARCHAR(150),\n`config_description` VARCHAR(250),\n`config_keyword` VARCHAR(250),\n`config_headtag` VARCHAR(250),\n`config_url` VARCHAR(150),\n`config_email` VARCHAR(150),\n`config_skin` VARCHAR(30) DEFAULT 'default',\n`config_language` VARCHAR(30) DEFAULT 'fr',\n`config_name` VARCHAR(30),\nPRIMARY KEY (`id`) \n) TYPE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;\n\n",
              "cms_session": "CREATE TABLE IF NOT EXISTS `cms_session` (\n`id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n`ses_ip` VARCHAR( 32 ) NOT NULL,\n`ses_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,\n`user_id` INT( 11 ),\nPRIMARY KEY ( `id` ) \n) TYPE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;\n\n",
              "cms_sale": "CREATE TABLE IF NOT EXISTS `cms_sale` (\n`id` INT(11) NOT NULL AUTO_INCREMENT,\n`session_id` INT(11) NOT NULL,\n`sale_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,\n`sale_content` TEXT NOT NULL,\n`sale_price` DECIMAL(10, 2) DEFAULT '0' NOT NULL,\n`sale_name` VARCHAR(150),\n`sale_addr` VARCHAR(150),\n`sale_email` VARCHAR(150) NOT NULL,\n`sale_phone` VARCHAR(16),\n`sale_note` VARCHAR(250),\n`sale_pay` VARCHAR(250),\n`sale_date_pay` TIMESTAMP NOT NULL,\nPRIMARY KEY (`id`) \n) TYPE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;\n\n",
             "cms_product": "CREATE TABLE IF NOT EXISTS  `cms_product` (\n`id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n`prod_ref` VARCHAR(20) DEFAULT 'aucune',\n`prod_desig` VARCHAR(100) NOT NULL,\n`prod_desc` VARCHAR(250) DEFAULT 'aucune',\n`prod_option` VARCHAR(250) DEFAULT '0' NOT NULL,\n`prod_img` VARCHAR(150) DEFAULT 'aucune' NOT NULL,\n`prod_price` DECIMAL(10,2) DEFAULT '0' NOT NULL,\n`prod_tax` DECIMAL(10,2) DEFAULT '0' NOT NULL,\n`prod_dispo` VARCHAR(3) DEFAULT 'oui' NOT NULL,\n`prod_stock` DECIMAL(10,2) DEFAULT  '1000' NOT NULL,\nPRIMARY KEY (`id`) \n) TYPE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;\n\n",
             "cms_help": "CREATE TABLE IF NOT EXISTS `cms_help` (\n`id` INT(11) NOT NULL AUTO_INCREMENT,\n`help_content` TEXT NOT NULL,\nPRIMARY KEY (`id`) \n) TYPE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;\n\n"
             }


  # SQL REQUEST **********************************************************************
  # USER TABLE
  select_all_from_user=u"SELECT * FROM `cms_user` ORDER BY `user_name`;"
  select_all_from_user_where_id=u"SELECT * FROM `cms_user` WHERE `id`=%s;"
  select_id_from_user_where_passwd=u"SELECT id FROM `cms_user` WHERE user_password='%s';"
  insert_user=u"INSERT INTO `cms_user` (`user_name`, `user_password`) VALUES ('%s', '%s');"
  last_insert_id_user=u"SELECT LAST_INSERT_ID() FROM `cms_user`;"
  update_user_where_id=u"UPDATE `cms_user` SET `user_name`='%s', `user_password`='%s'  WHERE `id`=%s;"
  delete_user_where_id=u"DELETE FROM `cms_user` WHERE `id`=%s;"
  backup_user=u"SELECT * FROM `cms_user` ORDER BY `id`;"

  
  # NAV TABLE
  select_all_from_nav=u"SELECT * FROM `cms_nav` WHERE `nav_parent_id` < 2 ORDER BY `nav_position`;"
  select_all_from_nav_where_parent=u"SELECT * FROM `cms_nav` WHERE `nav_parent_id`=%s ORDER BY `nav_position`;"
  update_nav_where_id=u"UPDATE `cms_nav` SET `nav_name`='%s', `nav_title`='%s', `nav_parent_id`=%s, `nav_position`=%s, `nav_onclick`='%s', `nav_selected`=%s, `page_id`=%s WHERE `id`=%s;"
  select_all_from_nav_where_id=u"SELECT * FROM `cms_nav` WHERE `id`=%s;"
  insert_nav=u"INSERT INTO `cms_nav` (`nav_name`, `nav_title`, `nav_parent_id`, `nav_position`, `nav_onclick`, `nav_selected`, `page_id`) VALUES ('%s', '%s', %s, %s, '%s', %s, %s );"
  last_insert_id_nav=u"SELECT LAST_INSERT_ID() FROM `cms_nav`;"
  delete_nav_where_pageid=u"DELETE FROM `cms_nav` WHERE `page_id`=%s;"
  backup_nav=u"SELECT * FROM `cms_nav` ORDER BY `id`;"

  
  # PAGE TABLE
  select_all_from_page_where_id=u"SELECT * FROM `cms_page` WHERE `id`=%s;"
  select_all_from_page=u"SELECT * FROM `cms_page` ORDER BY `id`;"
  update_page_where_id=u"UPDATE `cms_page` SET `page_title`='%s', `page_content`='%s', `nav_id`=%s WHERE `id`=%s;"
  insert_page=u"INSERT INTO `cms_page` (`page_title`, `page_content`, `nav_id`) VALUES ('%s', '%s', %s);"
  last_insert_id_page=u"SELECT LAST_INSERT_ID() FROM `cms_page`;"
  delete_page_where_id=u"DELETE FROM `cms_page` WHERE `id`=%s;"
  backup_page=u"SELECT * FROM `cms_page` ORDER BY `id`;"


  # CONFIG TABLE
  select_all_from_config_where_id=u"SELECT * FROM `cms_config` WHERE `id`=%s;"
  select_all_from_config=u"SELECT * FROM `cms_config` ORDER BY `id`;"
  select_id_from_config=u"SELECT `id` FROM `cms_config` ORDER BY `id`;"
  update_config_where_id=u"UPDATE `cms_config` SET `config_title`='%s', `config_pub`='%s', `config_description`='%s', `config_keyword`='%s', `config_headtag`='%s', `config_url`='%s', `config_email`='%s', `config_skin`='%s', `config_language`='%s', `config_name`='%s' WHERE `id`=%s;"
  insert_config=u"INSERT INTO `cms_config` (`config_title`, `config_pub`, `config_description`, `config_keyword`, `config_headtag`, `config_url`, `config_email`, `config_skin`, `config_language`, `config_name`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');"
  last_insert_id_config=u"SELECT LAST_INSERT_ID() FROM `cms_config`;"
  delete_config_where_id=u"DELETE FROM `cms_config` WHERE `id`=%s;"
  backup_config=u"SELECT * FROM `cms_config` ORDER BY `id`;"


  # SESSION TABLE
  insert_session=u"INSERT INTO `cms_session` (`ses_ip`) VALUES ('%s');"
  last_insert_id_session=u"SELECT LAST_INSERT_ID() FROM `cms_session`;"
  update_session_where_id=u"UPDATE `cms_session` SET `user_id`=%s WHERE `id`=%s;"
  select_all_from_session_where_id=u"SELECT * FROM `cms_session` WHERE `id`=%s;"
  delete_session_where_id=u"DELETE FROM `cms_session` WHERE `id`=%s;"
  backup_session=u"SELECT * FROM `cms_session` ORDER BY `id`;"

  
  # SALE TABLE
  select_all_from_sale_where_id=u"SELECT * FROM `cms_sale` WHERE id=%s;"
  insert_sale=u"INSERT INTO `cms_sale` (`session_id`, `sale_content`, `sale_price`, `sale_name`, `sale_addr`, `sale_email`, `sale_phone`, `sale_note`, `sale_pay`) VALUES (%s, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');"
  last_insert_id_sale=u"SELECT LAST_INSERT_ID() FROM `cms_sale`;"
  update_sale_where_id=u"UPDATE `cms_sale` SET `session_id`=%s, `sale_content`='%s', `sale_price`='%s', `sale_name`='%s', `sale_addr`='%s', `sale_email`='%s', `sale_phone`='%s', `sale_note`='%s', `sale_pay`='%s', `sale_date_pay`='%s'  WHERE `id`=%s;"
  update_sale_cust_where_id=u"UPDATE `cms_sale` SET `sale_name`='%s', `sale_addr`='%s', `sale_email`='%s', `sale_phone`='%s', `sale_note`='%s'  WHERE `id`=%s;"
  update_sale_pay_where_id=u"UPDATE `cms_sale` SET `sale_pay`='%s', `sale_date_pay`='%s'  WHERE `id`=%s;"
  delete_sale_where_id=u"DELETE FROM `cms_sale` WHERE `id`=%s;"
  backup_sale=u"SELECT * FROM `cms_sale` ORDER BY `id`;"


  # PRODUCT TABLE
  select_all_from_product=u"SELECT * FROM `cms_product` ORDER BY `prod_desig`;"
  select_all_from_product_where_id=u"SELECT * FROM `cms_product` WHERE id=%s;"
  update_product_where_id=u"UPDATE `cms_product` SET `prod_ref`='%s', `prod_desig`='%s', `prod_desc`='%s', `prod_option`='%s', `prod_img`='%s', `prod_price`='%s', `prod_tax`='%s', `prod_dispo`='%s', `prod_stock`='%s' WHERE `id`=%s;"
  insert_product=u"INSERT INTO `cms_product` (`prod_ref`, `prod_desig`, `prod_desc`, `prod_option`, `prod_img`, `prod_price`, `prod_tax`, `prod_dispo`, `prod_stock`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');"
  last_insert_id_product=u"SELECT LAST_INSERT_ID() FROM `cms_product`;"
  delete_product_where_id=u"DELETE FROM `cms_product` WHERE `id`=%s;"
  backup_product=u"SELECT * FROM `cms_product` ORDER BY `id`;"


  # HELP TABLE
  select_all_from_help=u"SELECT * FROM `cms_help` ORDER BY `id`;"
  select_all_from_help_where_id=u"SELECT * FROM `cms_help` WHERE `id`=%s;"
  insert_help=u"INSERT INTO `cms_help` (`help_content`) VALUES ('%s');"
  last_insert_id_help=u"SELECT LAST_INSERT_ID() FROM `cms_help`;"
  update_help_where_id=u"UPDATE `cms_help` SET `help_content`='%s' WHERE `id`=%s;"
  delete_help_where_id=u"DELETE FROM `cms_help` WHERE `id`=%s;"
  backup_help=u"SELECT * FROM `cms_help` ORDER BY `id`;"
